package tiled.simple.gwt.client;

import java.util.HashMap;

import tiled.simple.core.Renderer;

import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.user.client.ui.Image;


public class MapRenderer implements Renderer{

	//current context
	public Context2d context;
	
	private HashMap<String,Image> imagesCache = new HashMap<String, Image>();

	Camera camera;
	
	public MapRenderer(Camera camera) {
		this.camera=camera;
	}

	public void putImage(String source, int sx, int sy, int sw, int sh, int dx,int dy, int dw, int dh) {
		
			if(!imagesCache.containsKey(source)){
				imagesCache.put(source, new Image(source));
			}
			
			Image img=imagesCache.get(source);

			if(img!=null){
				ImageElement imageElement = ImageElement.as(img.getElement());

				context.drawImage(imageElement, sx, sy, sw, sh, dx,dy,dw, dh);
			}
	}

}
